{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "utcValue": {
            "type": "string",
            "defaultValue": "[utcNow('yyyyMMddHHmmss')]",
            "metadata": {
                "description": "The UTC value."
            }
        },
        "availabilityZones": {
            "type": "array",
            "defaultValue": [],
            "metadata": {
                "description": "The availability zones for the container group."
            }
        },
        "location": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]",
            "metadata": {
                "description": "The location for the container group.  Don't change this value!"
            }
        },
        "containerName": {
            "type": "string",
            "defaultValue": "cohere-toolkit",
            "metadata": {
                "description": "The name of the container."
            }
        },
        "imageType": {
            "type": "string",
            "allowedValues": [
                "Public",
                "Private"
            ],
            "defaultValue": "Private",
            "metadata": {
                "description": "The type of Docker image."
            }
        },
        "imageName": {
            "type": "string",
            "defaultValue": "ghcr.io/cohere-ai/cohere-toolkit",
            "metadata": {
                "description": "The name of the Docker image."
            }
        },
        "osType": {
            "type": "string",
            "allowedValues": [
                "Linux",
                "Windows"
            ],
            "defaultValue": "Linux",
            "metadata": {
                "description": "The operating system type."
            }
        },
        "numberCpuCores": {
            "type": "string",
            "defaultValue": "3",
            "metadata": {
                "description": "The number of CPU cores."
            }
        },
        "memory": {
            "type": "string",
            "defaultValue": "8",
            "metadata": {
                "description": "The amount of memory in GB."
            }
        },
        "restartPolicy": {
            "type": "string",
            "allowedValues": [
                "OnFailure",
                "Always",
                "Never"
            ],
            "defaultValue": "OnFailure",
            "metadata": {
                "description": "The restart policy for all containers within the container group."
            }
        },
        "sku": {
            "type": "string",
            "allowedValues": [
                "Standard",
                "Confidential"
            ],
            "defaultValue": "Standard",
            "metadata": {
                "description": "The SKU of the container group."
            }
        },
        "cohereApiKey": {
            "type": "secureString",
            "metadata": {
                "description": "The API key for the Cohere API."
            }
        },
        "frontendPort": {
            "type": "string",
            "defaultValue": "4000",
            "metadata": {
                "description": "The port of the frontend."
            }
        },
        "backendPort": {
            "type": "string",
            "defaultValue": "8000",
            "metadata": {
                "description": "The port of the backend API."
            }
        },
        "ipAddressType": {
            "type": "string",
            "allowedValues": [
                "Public",
                "Private"
            ],
            "defaultValue": "Public",
            "metadata": {
                "description": "The type of IP address."
            }
        },
        "ports": {
            "type": "array",
            "defaultValue": [
                {
                    "port": 8000,
                    "protocol": "TCP"
                },
                {
                    "port": 4000,
                    "protocol": "TCP"
                }
            ],
            "metadata": {
                "description": "The ports for the container group."
            }
        },
        "dnsNameLabel": {
            "type": "string",
            "defaultValue": "toolkit-app",
            "metadata": {
                "description": "The DNS name label for the container."
            }
        },
        "autoGeneratedDomainNameLabelScope": {
            "type": "string",
            "defaultValue": "Unsecure",
            "metadata": {
                "description": "The scope of the auto-generated domain name label."
            }
        }
    },
    "resources": [
        {
            "location": "[parameters('location')]",
            "name": "[parameters('containerName')]",
            "type": "Microsoft.ContainerInstance/containerGroups",
            "apiVersion": "2021-09-01",
            "zones": "[parameters('availabilityZones')]",
            "properties": {
                "containers": [
                    {
                        "name": "[parameters('containerName')]",
                        "properties": {
                            "image": "[parameters('imageName')]",
                            "resources": {
                                "requests": {
                                    "cpu": "[int(parameters('numberCpuCores'))]",
                                    "memoryInGB": "[float(parameters('memory'))]"
                                }
                            },
                            "environmentVariables": [
                                {
                                    "name": "COHERE_API_KEY",
                                    "secureValue": "[parameters('cohereApiKey')]"
                                },
                                {
                                    "name": "NEXT_PUBLIC_API_HOSTNAME",
                                    "value": "[concat('http://',parameters('dnsNameLabel'),'-',parameters('utcValue'),'.',parameters('location'),'.azurecontainer.io',':',parameters('backendPort'))]"
                                },
                                {
                                    "name": "PORT",
                                    "value": "[parameters('frontendPort')]"
                                }
                            ],
                            "ports": "[parameters('ports')]"
                        }
                    }
                ],
                "restartPolicy": "[parameters('restartPolicy')]",
                "osType": "[parameters('osType')]",
                "sku": "[parameters('sku')]",
                "ipAddress": {
                    "type": "[parameters('ipAddressType')]",
                    "ports": "[parameters('ports')]",
                    "dnsNameLabel": "[concat(parameters('dnsNameLabel'),'-',parameters('utcValue'))]",
                    "autoGeneratedDomainNameLabelScope": "[parameters('autoGeneratedDomainNameLabelScope')]"
                }
            },
            "tags": {}
        }
    ]
}